package com.web.manager.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.web.manager.pojo.Major;
import com.web.manager.mapper.CourseMapper;
import com.web.manager.mapper.MajorMapper;
import com.web.manager.pojo.Course;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CourseService extends ServiceImpl<CourseMapper, Course> {
    @Resource
    private MajorMapper majorMapper;

    @Resource
    private CourseMapper courseMapper;

    @Override
    public boolean save(Course entity){

        int a  = courseMapper.selectType(entity.getBelong());
        Major major = majorMapper.selectType2(entity.getBelong());
        major.setNum(a+1);
        majorMapper.updateById(major);
        return super.save(entity);
    }


    public Course selectByUsername(String name){
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>(); //条件查询器
        queryWrapper.eq("name",name);  // ==> where username = #{username}


        // 根据用户名查询数据库的用户信息
        return  this.getOne(queryWrapper); // ==>select * from manager_user where username = #{username}
    }
}
